package com.yzw.endecoderline;

import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.FixedLengthFrameDecoder;
import io.netty.handler.codec.LineBasedFrameDecoder;
import io.netty.handler.codec.string.StringDecoder;
import io.netty.handler.codec.string.StringEncoder;

/**
 * @Author: YangZhenWei
 * @PROJECT_NAME: nettyTeach
 * @DESCRIPTION: 客户器端 handle初始化配置类,配置 加密器
 * @USER: root
 * @DATE: 2023/2/9 23:36
 **/
public class InitializerClientEnDeCoder  extends ChannelInitializer<SocketChannel> {
    @Override
    protected void initChannel(SocketChannel socketChannel) throws Exception {
        ChannelPipeline pipeline = socketChannel.pipeline();
        // handler的别名
        pipeline.addLast("framer",new LineBasedFrameDecoder(CommonUtils.LINELENGTHFRAME_LENGTH,false,true));// 定义行解码器
        pipeline.addLast("decoder",new StringDecoder());
        pipeline.addLast("encoder",new StringEncoder());
        // 行解码器设置
        pipeline.addLast(new HandlerClientLineBased());// 自定义业务逻辑的handler

    }
}
